package 面向对象.实验9;

/**
 * @author IT_Jay
 * @date 2021/12/2 10:19
 */

public class TestThread {
    public static void main(String[] args) {
        Thread t1 = new TestThread1();
        Thread t4 = new Thread(t1,"t1");

        TestThread2 t2 = new TestThread2();
        Thread t3 = new Thread(t2,"t3");
//        t1.start();
        t4.start();

//        t2.run();
        t3.start();
    }
}

class TestThread1 extends Thread{
    @Override
    public void run(){
        int sum = 0;
        for (int i=101;i<=500;i=i+2){
            sum += i;
        }
        System.out.println("奇数和为："+sum);
        System.out.println(Thread.currentThread().getName()+" is running");
    }
}

class TestThread2 implements Runnable{

    @Override
    public void run() {
        int sum = 0;
        for (int i=102;i<=500;i=i+2){
            sum += i;
        }
        System.out.println("偶数和为："+sum);
        System.out.println(Thread.currentThread().getName()+" is running");
    }
}